﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CounterServerModel;
using System.Data;
using CounterServerModel.Authentication;

namespace SmartCounters
{
	public partial class BillingInfoManagement : System.Web.UI.Page
	{
		DataTable billingInfoTable;

		protected void Page_Load(object sender, EventArgs e)
		{
			((MainTemplate)Master).m_PagePermissionFilter = MainTemplate.k_AdminPageFilter;
		}

		protected void Page_Prerender(object sender, EventArgs e)
		{
			BillingService billingService = new BillingService();

			billingInfoTable = billingService.GetBillingInfoTable(((MainTemplate)Master).AuthenticatedLoggedInUserCredentials);
			BindGrid();

		}

		protected void AddBillingInfo(object sender, EventArgs e)
		{
			BillingService billingService = new BillingService();
			string comment = tbComments.Text;
			double newPrice = double.Parse(tbPrice.Text);
			billingService.SetCurrentPrice(((MainTemplate)Master).AuthenticatedLoggedInUserCredentials, newPrice, comment);

			clearForm();
		}

		private void BindGrid()
		{
			BillingInfoGrid.DataSource = billingInfoTable;
			BillingInfoGrid.DataBind();
		}

		private void clearForm()
		{
			tbComments.Text = "";
			tbPrice.Text = "";
		}
	}
}